package ncme.auto.framework.core.entities.aspect.autoParam;

import ncme.auto.framework.core.entities.ResMsg;

import java.util.HashMap;
import java.util.Map;

public class ResInAuto {

    private Object result;

    private Map<String, Object> paramForSwitch = new HashMap<>();

    private Map<String, Object> extraResult = new HashMap<>();

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public ResInAuto(Object result) {
        this.result = result;
    }

    public ResInAuto(Object result, String msg) {
        this.result = result;
        paramForSwitch.put("msg", msg);
    }

    public ResInAuto(Object result, String msg, Integer code) {
        this.result = result;
        paramForSwitch.put("msg", msg);
        paramForSwitch.put("code", code);
    }

    public static ResInAuto fromResMsg(ResMsg resMsg) {
        ResInAuto res = new ResInAuto(null);
        if (resMsg == null) {
            res.result = null;
            res.paramForSwitch.put("code", -1);
            res.paramForSwitch.put("msg" + "！！！非正常输出，需修复", null);
            res.paramForSwitch.put("resMsg", null);
            return res;
        }
        res.result = resMsg.getData();
        res.paramForSwitch.put("code", resMsg.getCode());
        res.paramForSwitch.put("msg" + "！！！非正常输出，需修复", resMsg.getMsg());
        res.paramForSwitch.put("resMsg", resMsg);
        return res;
    }

    //创建实体的新id
    public Integer getInsertId() {
        Object newId = this.paramForSwitch.get("newId");
        return (Integer) newId;
    }

    public void setInsertId(Integer newId) {
        this.paramForSwitch.put("newId", newId);
    }

    //查询结果的数量
    public Integer getResultNum() {
        Object resultNum = this.paramForSwitch.get("resultNum");
        return (Integer) resultNum;
    }

    public void setResultNum(Integer num) {
        this.paramForSwitch.put("resultNum", num);
    }

    //信息
    public String getMsg() {
        Object msg = this.paramForSwitch.get("msg");
        return (String) msg;
    }

    public void setMsg(String msg) {
        this.paramForSwitch.put("msg", msg);
    }

    //code
    public Integer getCode() {
        Object newId = this.paramForSwitch.get("code");
        return (Integer) newId;
    }

    public void setCode(Integer code) {
        this.paramForSwitch.put("code", code);
    }

    //resMsg
    public ResMsg getResMsg() {
        Object resMsg = this.paramForSwitch.get("resMsg");
        return (ResMsg) resMsg;
    }
}
